﻿#region 命名空间

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using WinnerCMS.BLL;
using WinnerCMS.Model;
using WinnerCMS.Common;
using WinnerCMS.Model.Attribute;

#endregion

namespace WinnerCMS.WebUI.Admin.Counter
{
    [Access("270001")]
    public partial class Main : WebFactory.PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            CounterContent_Result();
            this.lblPath.Text = " 访问统计 → 访问统计概况";
        }

        #region 统计

        public void CounterContent_Result()
        {
            var model = new CounterContentManage().GetInfo();
            if (model == null)
            {
                MsgBox.Message("统计系统还没有启用。", this);
                return;
            }

            long itotal;
            string stronline;
            long itoday;
            long iyesterday;
            double dbldays;
            double dbldayavg;
            int iguess;

            string strhightime;


            //总访问数 
            itotal = model.Total;
            this.lbl总访问量.Text = model.Total.ToString();

            //开始访问日期

            this.lbl开始统计于.Text = model.StartTime.ToShortDateString();
            if (itotal == 0)
            {
                MsgBox.Message("统计系统还没有启用。", this);
                return;
            }

            //最高访问数
            this.lbl最高访问量.Text = model.High.ToString();


            //最高访问数发生日期
            strhightime = model.HighTime.Date.ToShortDateString();
            this.lbl最高量日期.Text = strhightime;


            //在线人数
            stronline = new CounterDiaryManage().TotalOnline().ToString();
            this.lbl在线人数.Text = stronline;


            //今日访问量、昨日访问量 
            if (model != null)
            {
                itoday = model.Today;
                iyesterday = model.Yesterday;
            }
            else
            {
                itoday = 0;
                iyesterday = 0;
            }
            this.lbl今日访问量.Text = model.Today.ToString();
            this.lbl昨日访问量.Text = model.Yesterday.ToString();


            //今年访问量（从主数据库读取）
            this.lbl今年访问量.Text = new CounterDiaryManage().ThisYear();

            //本月访问量

            this.lbl本月访问量.Text = new CounterDiaryManage().ThisMonth();

            //访问天数 
            dbldays = DateTime.Now.Subtract(model.StartTime).TotalDays;

            this.lbl统计天数.Text = Convert.ToInt32(dbldays).ToString();

            //平均每天访问量
            dbldayavg = itotal/dbldays;
            this.lbl平均日访量.Text = dbldayavg.ToString();

            var dbcf = Math.Pow(10, 5);
            dbldays = (int) (dbldays*dbcf + 0.5)/dbcf;
            dbldayavg = (int) (dbldayavg*dbcf + 0.5)/dbcf;

            //预计今日访问量
            var dblvdaylong = DateTime.Now.Subtract(DateTime.Now.Date).TotalDays;
            iguess = (int) (((itoday/dblvdaylong) + iyesterday)/2 + 0.5);
            if (iguess < itoday)
                iguess = (int) ((itoday/dblvdaylong) + 0.5);

            this.lbl预计今日.Text = iguess.ToString();
        }

        #endregion
    }
}